<html>

<head>
    <meta charset="UTF-8">
    <title>厂商列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/bass.css"/>
    <style>
        #search{
            margin-top: -5px;
        }
    </style>
</head>
<body>
<div class="body accountsShop">
    <header class="layui-nav" id="headerTop"></header>
    <div class="left_muen" id="left_menu"></div>
    <div class="content_body">
        <p class="content_title">设备管理 &nbsp;&nbsp;>&nbsp;&nbsp;厂商列表</p>

        <div class="content_seach">
            <form class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">厂商名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="devicename" autocomplete="off" class="layui-input" placeholder="请输入设备名称">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">厂商类型</label>

                        <div class="layui-input-inline">
                            <select name="devicetype" lay-verify="required" lay-search="">
                                <option value="1">供应商</option>
                                <option value="2">厂家</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-btn layui-btn-warm search layui-btn-sm" id="search"  lay-submit=""  lay-filter="search"><i class="layui-icon">&#xe615;</i>查询</div>
                </div>
            </form>
        </div>
        <div class="content_table">
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="addCheckData"><i class="layui-icon">&#xe654;</i>添加</button>
                    <button class="layui-btn layui-btn-sm" lay-event="delCheckData"><i class="layui-icon">&#xe640;</i>删除</button>
                </div>
            </script>
            <div class="tabTable">
                <table id="table" lay-filter="tableFilter"></table>
                <div class="layui-table-page fr">
                	<div id="layui-table-page1"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="barContractUpdate">
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
</script>
<script type="text/html" id="maTypeTemplet">
	{{#if (d.maType == 1) { }}
	 供应商
	{{# }else if(d.maType == 2){ }}
	 厂家
	{{# } }}
</script>
<script src="../../js/common/jquery-1.11.3.min.js"></script>
<script src="../../layui/layui.js"></script>
<script src="../../js/common/navList.js"></script>
<script src="../../js/common/ajax.js"></script>
<script>
    layui.use(['table','form'], function () {
        var table = layui.table;
        var form = layui.form;
//      pageNo = href.split("#")?href.split("#")[1].split("=")[1]:1;
        //第一个实例
        ajaxTable({
            idNode: '#table',
            url: 'manufacturer/getList',
            dataCols: [
                {fixed: true, checkbox: true, height: 180},
                {field: 'id', title: '厂商编号',align: 'center',sort: true},
                {field: 'maTitle', title: '简称',align: 'center'},
                {field: 'maAllTitle', title: '全称',align: 'center'},
                {field: 'uploadCycle', title: '上传周期',align: 'center',sort: true},
                {field: 'maType', title: '厂商类型',align: 'center',templet:'#maTypeTemplet'},
                {field: 'maDesc', title: '描述',align: 'center'},
                {field: 'right', title: '操作', width: 170, toolbar: "#barContractUpdate"}
            ],
            successFull: function (res, curr, count,table) {
                table.on('toolbar(tableFilter)', function(obj){
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    if(obj.event == 'addCheckData'){
                        window.location.href = './shopAdd.html?pos=0&childPos=1'
                    };
                    if(obj.event == 'delCheckData') {
                        if (data.length <= 0) {
                            layer.msg('请勾选要删除的站点', {
                                icon: 6
                            });
                        }else{
                            layer.confirm('确定删除吗？', function (index) {
                            var ids = [];
                            $.each(data,function(i,item){
                                ids.push(item.id)
                            });
                            $.ajax({
                                url: baseUrl + "manufacturer/batchDel",
                                type: "POST",
                                data: {
                                    ids: ids
                                },
                                dataType: "json",
                                success: function (data) {
                                    if (data.code == 200) {
                                        updata()
                                        layer.msg("删除成功", {icon: 6});
                                    } else {
                                        layer.msg("删除失败", {icon: 5});
                                    }
                                }
                            })
                            });
                        }
                    }
                })
            }
        });
        form.on('submit(search)', function(data){
            data.field.devicename = !data.field.devicename?"":data.field.devicename;
            ajaxTable({
                idNode: '#table',
                url: 'manufacturer/getList',
                urlParme:'&maTitle='+data.field.devicename+'&maType='+data.field.devicetype,
                dataCols: [
                    {fixed: true, checkbox: true, height: 180},
                    {field: 'id', title: '厂商编号',sort: true},
                    {field: 'maTitle', title: '简称',},
                    {field: 'maAllTitle', title: '全称'},
                    {field: 'uploadCycle', title: '上传周期',sort: true},
                    {field: 'maType', title: '厂商类型',templet:'#maTypeTemplet'},
                    {field: 'maDesc', title: '描述'},
                    {field: 'right', title: '操作', width: 170, toolbar: "#barContractUpdate"}
                ],
                successFull: function (res, curr, count) {

                }
            });
        })
        //监听工具条
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('确定删除吗？', function (index) {
                    console.log(data);
                    $.ajax({
                        url: baseUrl + "/manufacturer/del",
                        type: "POST",
                        data: {"id": data.id},
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                obj.del();
                                layer.close(index);
                                layer.msg("删除成功", {icon: 6});
                            } else {
                                layer.msg("删除失败", {icon: 5});
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                layer.confirm('确定修改吗？', function (index) {
                    location.href = "./shopEdit.html?pos=0&childPos=1&id=" + data.id;
                });
            }
        });
    });
    function updata(){
        ajaxTable({
            idNode: '#table',
            url: 'manufacturer/getList',
            dataCols: [
                {fixed: true, checkbox: true, height: 180},
                {field: 'id', title: '厂商编号'},
                {field: 'maTitle', title: '简称',},
                {field: 'maAllTitle', title: '全称'},
                {field: 'uploadCycle', title: '上传周期'},
                {field: 'maType', title: '设备类型'},
                {field: 'maDesc', title: '描述'},
                {field: 'right', title: '操作', width: 170, toolbar: "#barContractUpdate"}
            ],
            successFull: function (res, curr, count) {

            }
        });
    }
</script>
</body>

</html>